﻿Imports System
Imports System.IO
Imports System.Data.OleDb
Imports System.Data
Imports System.Net.Mail
Namespace Arwani
    Partial Class Footer
        Inherits System.Web.UI.UserControl
        Protected Sub lnkSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSend.Click

            'First Save Data in Database

            Dim strQ As String
            Dim arwCon As New ArwaniController

          
            strQ = "INSERT INTO Contact (Name,Phone,Email,Message) VALUES ('" & txtName.Text & "','" & txtPhone.Text & "','" & txtEmail.Text & "', '" & txtMessage.Text & "')"
            arwCon.ExecuteNonQuery(strQ)




            Dim strMessage As String = ""
            strMessage = "Following information has been sent in the contact form<br>"
            strMessage &= "Name : " & Me.txtName.Text & "<Br>"
            strMessage &= "Phone : " & Me.txtPhone.Text & "<Br>"
            strMessage &= "Email : " & Me.txtEmail.Text & "<Br>"
            strMessage &= "Message : " & Me.txtMessage.Text & "<Br>"

          


            Dim title As [String] = "Contact From - Arwani Trading Website"
            Dim toAccount As [String] = " ae.arwani@gmail.com"
            'Dim toAccount As [String] = "sahilk@nascenture.com"

            'String toAccount = "niteshguleria@nascenture.com";
            Dim MyHost As [String] = "smtp.gmail.com"
            Dim MySMTPPort As [String] = "587"
            Dim MySMTPSSL As [String] = "true"
            Dim fromAddr As [String] = txtEmail.Text.ToString()
            'Email Address of Sender
            Dim smtpMssg As New MailMessage()
            smtpMssg.From = New MailAddress(fromAddr)
            If toAccount.Contains(",") Then
                Dim tos As String() = toAccount.Split(","c)
                For i As Integer = 0 To tos.Length - 1
                    If tos(i) = "," OrElse tos(i) = "" Then
                    Else
                        smtpMssg.[To].Add(New MailAddress(tos(i).Replace(",", "")))
                    End If
                Next
            Else
                smtpMssg.[To].Add(New MailAddress(toAccount))
            End If
            smtpMssg.Subject = title
            smtpMssg.Body = strMessage
            smtpMssg.IsBodyHtml = True
            Dim smtpClient As New System.Net.Mail.SmtpClient(MyHost, Convert.ToInt32(MySMTPPort))
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
            If MySMTPSSL = "true" Then
                smtpClient.EnableSsl = True
            End If

            Try
                smtpClient.Send(smtpMssg)
                Me.lblErrorMessage.Visible = True
                Me.lblErrorMessage.InnerText = "We look forward to receive your valuable inquiries, please feel to contact us and one of our sales specialist will contact you for any queries you may have."



            Catch ex As Exception
                Throw New Exception("Email not sent | Reason: [" + ex.Message & "]")
            End Try
            Me.lblErrorMessage.Visible = True
            Me.txtName.Text = String.Empty
            Me.txtPhone.Text = String.Empty
            Me.txtEmail.Text = String.Empty
            Me.txtMessage.Text = String.Empty
           






















        End Sub
    End Class
End Namespace